package model

import (
	"github.com/doujunyu/gogo/sql_aid"
	"go_self/util"
)

const TableByUser = "self_user"

const UserByStatusNormal = 1 //正常
const UserByStatusForbid = 2 //禁用

func UserByStatusString(status int) string {
	stringMpa := map[int]string{
		UserByStatusNormal: "正常",
		UserByStatusForbid: "禁用",
	}
	return stringMpa[status]
}

// UserByInfo 个人信息
func UserByInfo(userId int64) map[string]interface{} {
	userSql, args := sql_aid.PgTable(TableByUser).Field("id", "username", "mobile", "nick", "avatar", "status").Where("id = ?", userId).ToSql()
	userData, err := sql_aid.DataToMap(PgSql.Query(userSql, args...))
	if err != nil || len(userData) == 0 {
		return nil
	}
	userData[0]["avatar"] = util.NilToString(userData[0]["avatar"], "")
	userData[0]["mobile"] = util.NilToString(userData[0]["mobile"], "")
	return userData[0]
}
